//
//  FadBackView.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/29.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "FadBackView.h"

@implementation FadBackView
- (instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
        [self initSubView];
        [self layout];
    }
    return self;
}
- (void)initSubView{
    self.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.navView];
    [self addSubview:self.tv];
    [self addSubview:self.confirmButton];
}
- (void)layout{
    [_navView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.height.equalTo(@44);
    }];
    [_tv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.width.equalTo(@600);
        make.top.equalTo(@83);
        make.height.equalTo(@220);
    }];
    [_confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.width.equalTo(@269);
        make.top.equalTo(self->_tv.mas_bottom).offset(45);
        make.height.equalTo(@40);
    }];
}
- (ZXFDCCVNav *)navView{
    if (!_navView) {
        ZXFDCCVNav *view = [[ZXFDCCVNav alloc]init];
        view.backgroundColor = [UIColor whiteColor];
        view.delegate = self;
        view.titleLabe.text = @"意见反馈";
        _navView = view;
    }
    return _navView;
}
- (void)backClick{
    [UIView animateWithDuration:0.5 animations:^{
        self.frame = CGRectMake(self.frame.size.width, 0, self.frame.size.width, self.frame.size.height);
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
    
}
- (UITextView *)tv{
    if (!_tv) {
        UITextView *view = [[UITextView alloc]init];
        view.layer.cornerRadius = 5;
        view.layer.masksToBounds = YES;
        view.layer.borderColor = LINCOLOR.CGColor;
        view.layer.borderWidth = 1;
        view.delegate  =self;
        view.textColor  =[UIColor darkGrayColor];
        _placeHolder = [[UILabel alloc]init];
        _placeHolder.frame = CGRectMake(10, 10, 120, 15);
        _placeHolder.textColor =LINCOLOR;
        _placeHolder.text =@"请填写您的意见，我们会不断改进";
        _placeHolder.font = [UIFont systemFontOfSize:16];
        [view addSubview:_placeHolder];
        _tv = view;
    }
    return _tv;
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if (textView.text.length>0) {
        _placeHolder.hidden = YES;
    }else{
        _placeHolder.hidden = NO;
    }
    return YES;
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    if (textView.text.length>0) {
        _placeHolder.hidden = YES;
    }else{
        _placeHolder.hidden = NO;
    }
    return YES;
}
- (UIButton *)confirmButton{
    if (!_confirmButton) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@"提交" forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:16];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        button.layer.cornerRadius = 5;
        button.layer.masksToBounds = YES;
        [button setBackgroundImage:[UIImage imageWithColor:SELECTEDCOLOR forSize:CGSizeMake(200, 200)] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(confirm:) forControlEvents:UIControlEventTouchUpInside];
        _confirmButton = button;
    }
    return _confirmButton;
}
- (void)confirm:(UIButton *)sender{
    
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self endEditing:YES];
}
@end
